<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>申请退车</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<script type="text/javascript">
    var userId = '${userId}';
    var changeTypeCd = '${changeTypeCd}';
    var grid = null;
    $(function () {
        initForm();
        initGrid();
    });

    //清空按钮事件
    function clearBtn() {
        $("#resetBtn").click();
        var form = new liger.get("searchBar");
        form.setData({
            "certNo": " ",
            "cstNm": " ",
            "paySchNo": " ",
            "lsCntNo": " "
        });
    }

    //初始化表单
    function initForm() {
        $("#searchBar").ligerForm();
    }

    //查询按钮事件
    function searchBtn() {
        var form = new liger.get("searchBar");
        var data = form.getData();
        data["userId"] = $("#userId").val();
        for (name in data) {
            grid.setParm(name, data[name]);
        }
        grid.reload();
    }

    //查询参数
    function getSearchParams() {
        var form = liger.get("searchBar");
        var data = form.getData();
        data["userId"] = '${userId}';
        data["changeTypeCd"] = '${changeTypeCd}';
        return data;
    }

    //初始化列表
    function initGrid() {
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/changeapply/prjPrdChangeApply/initChangeList.do',
            method: 'get',
            parms: getSearchParams(),
            columns: [
                {display: "客户名称", name: 'cstNm', minWidth: 100, enabledSort: true},
                {display: '证件/组织机构代码', name: 'certNo', minWidth: 200, enabledSort: true},
                {display: '合同号', name: 'lsCntNo', minWidth: 200, enabledSort: true},
                {display: '支付表号', name: 'paySchNo', minWidth: 200, enabledSort: true}
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
    }


    function detailBtn(){
        var selectedRows = grid.getSelectedRows();
        if(selectedRows.length != 1){
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
            return;
        }
        var prjId = selectedRows[0].prjId;
        var paySchId = selectedRows[0].paySchId;
        var params = "?paySchId="+paySchId+"&&changeTypeCd="+changeTypeCd;

        //确定逻辑：资管多台车不可，到第一期还款日不可
        var _url = '<%=path%>/changeapply/prjPrdChangeApply/changeCheck.do';
        $.ajax({
            type: 'get',
            dataType:'json',
            data:{
                prjId: prjId,
                paySchId: paySchId,
                changeTypeCd: changeTypeCd
            },
            url: _url,
            success:function(msg){
                if(msg.success == 1){
                    var callback = frameElement.dialog.get("callback");
                    if (changeTypeCd=='1'){
                        parent.Add_navTab('tab_change_apply_detail' + paySchId,'退车申请',
                            '<%=path%>/changeapply/prjPrdChangeApply/toAddPage.do'+params,callback);
                    } else if (changeTypeCd=='2'){
                        parent.Add_navTab('tab_change_apply_detail' + paySchId,'换车申请',
                            '<%=path%>/changeapply/prjPrdChangeApply/toAddPageForHC.do'+params,callback);
                    }
                    parent.$.ligerDialog.close();
                    parent.$(".l-dialog,.l-window-mask").css("display","none");
                }else {
                    top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                }
            }
        });
    }
</script>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">证件号</div>
                    <div class="field">
                        <input name="certNo" id="certNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round" onclick="searchBtn()">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round" onclick="clearBtn()">清空</span>
                    <span id="detailBtn" class="sq-button sq-button-round" onclick="detailBtn()">确定</span>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>
</body>
</html>